// store.ts
import { InjectionKey } from 'vue';
import { createStore, useStore as baseUseStore, Store } from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import app, { AppState } from './modules/app';

const shadow = {};

export interface RootState {
    version: string
}
export interface State {
    app: AppState,
    shadow: {
        token: string
    }
}

export const key: InjectionKey<Store<State>> = Symbol();

// NOTICE: 这里如果修改成了 localStorage 则
// 退出登录，或者进行页面切换的时候需要手动的进行清理
const plugins = [
    createPersistedState({
        storage: window.sessionStorage,
    }),
];
export const store = createStore<State>({
    plugins,
    modules: {
        app,
        shadow
    },
});

// 定义自己的 `useStore` 组合式函数
export function useStore() {
    return baseUseStore(key);
}
